import 'package:flutter/material.dart';
import 'package:hy/common/values/values.dart';
import 'package:hy/modules/home/models/home_list_model.dart';

class HomeListUnitWidget extends StatefulWidget {
  final HomeListElementResponseModel responseModel;
  const HomeListUnitWidget({Key? key, required this.responseModel})
      : super(key: key);

  @override
  State<HomeListUnitWidget> createState() => _HomeListUnitWidgetState();
}

class _HomeListUnitWidgetState extends State<HomeListUnitWidget> {
  late ScrollController _sliverScrollController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    _sliverScrollController = ScrollController();
  }

  @override
  void dispose() {
    _sliverScrollController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        GridView.builder(
          controller: _sliverScrollController,
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          padding: const EdgeInsets.all(10),
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3,
            mainAxisSpacing: 10,
            crossAxisSpacing: 10,
            childAspectRatio: 1.0,
          ),
          itemBuilder: (context, index) {
            return Container(
              decoration: BoxDecoration(
                color: AppColor.colorDarkCyan,
                borderRadius: Radii.k6pxRadius,
                image: DecorationImage(
                  image: AssetImage(
                    widget.responseModel.images[index],
                  ),
                ),
              ),
            );
          },
          itemCount: widget.responseModel.images.length,
        ),
        Padding(
          padding: const EdgeInsets.all(10.0),
          child: Text(
            "${widget.responseModel.time}  ${widget.responseModel.device}",
            style: TextStyle(
              color: AppColor.colorLightGrey,
              fontSize: 12,
            ),
          ),
        ),
      ],
    );
  }
}
